package com.example.carport.controller;

import com.example.carport.service.CarportService;
import com.example.entity.Carport;
import com.example.result.CommonResult;
import com.example.utils.MyPageHelper;
import com.example.utils.PageRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/carport")
public class CarportController {
    @Autowired
    CarportService carportService;
    /**
     * 停车场管理-车位全查
     * @return
     */
    @GetMapping("/getCarport")
    public CommonResult getCarport(@RequestParam String carportCustomerBinding, PageRequest pageRequest){
        MyPageHelper.StartPage(pageRequest);
        CommonResult commonResult = carportService.getCarport(carportCustomerBinding);
        return commonResult;
    }
    /**
     * 停车场管理-车位删除
     */
    @DeleteMapping("/delCarport")
    public CommonResult delCarport(Integer id){
        int i = carportService.delCarport(id);
        return CommonResult.ok(i);
    }
    /**
     * 车辆管理-车位增改
     */
    @PostMapping("/saveOrUpdateCarport")
    public CommonResult saveOrUpdateCarport(MultipartFile file, Carport carport){
        int i = carportService.saveOrUpdateCarport(file,carport);
        if(i>0){
            return CommonResult.ok();
        }else{
            return CommonResult.fail();
        }
    }
    /**
     * 车辆管理-车位审批
     */
    @GetMapping("/getApprover")
    public CommonResult getApprover(PageRequest pageRequest){
        MyPageHelper.StartPage(pageRequest);
        CommonResult commonResult = carportService.getApprover();
        return commonResult;
    }
    /**
     * 车辆管理-车位审批通过
     */
    @GetMapping("/getPassApprover")
    public CommonResult getPassApprover(PageRequest pageRequest){
        MyPageHelper.StartPage(pageRequest);
        CommonResult commonResult = carportService.getPassApprover();
        return commonResult;
    }
    /**
     * 车辆管理-车位未通过
     */
    @GetMapping("/getRejectApprover")
    public CommonResult getRejectApprover(PageRequest pageRequest){
        MyPageHelper.StartPage(pageRequest);
        CommonResult commonResult = carportService.getRejectApprover();
        return commonResult;
    }
    /**
     * 停车场管理-车位审批通过
     */
    @DeleteMapping("/passApprover")
    public CommonResult passApprover(Integer id){
        int i = carportService.passApprover(id);
        return CommonResult.ok(i);
    }
    /**
     * 停车场管理-车位驳回
     */
    @DeleteMapping("/rejectApprover")
    public CommonResult rejectApprover(Integer id){
        int i = carportService.rejectApprover(id);
        return CommonResult.ok(i);
    }
}
